home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
qltk
/
browser.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
13KB
|
315 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
from gi.repository import Gtk, Pango
from quodlibet import config
from quodlibet import util
from quodlibet import browsers
from quodlibet import app
from quodlibet.qltk.songlist import SongList
from quodlibet.qltk.x import ScrolledWindow
from quodlibet.qltk.window import Window, PersistentWindowMixin
from quodlibet.util.library import background_filter
class FilterMenu(object):
_MENU = "\n <ui>\n <menubar name='Menu'>\n <menu action='Filters'>\n <menuitem action='FilterGenre' always-show-image='true'/>\n <menuitem action='FilterArtist' always-show-image='true'/>\n <menuitem action='FilterAlbum' always-show-image='true'/>\n <separator/>\n <menuitem action='RandomGenre' always-show-image='true'/>\n <menuitem action='RandomArtist' always-show-image='true'/>\n <menuitem action='RandomAlbum' always-show-image='true'/>\n <separator/>\n <menuitem action='All' always-show-image='true'/>\n <menuitem action='PlayedRecently' always-show-image='true'/>\n <menuitem action='AddedRecently' always-show-image='true'/>\n <menuitem action='TopRated' always-show-image='true'/>\n </menu>\n </menubar>\n </ui>"
def __init__(self, library, player, ui = None):
self._browser = None
self._library = library
self._player = player
ag = Gtk.ActionGroup.new('QuodLibetFilterActions')
ag.add_actions([
('Filters', None, _('_Filters')),
('PlayedRecently', Gtk.STOCK_FIND, _('Recently _Played'), '', None, self._FilterMenu__filter_menu_actions),
('AddedRecently', Gtk.STOCK_FIND, _('Recently _Added'), '', None, self._FilterMenu__filter_menu_actions),
('TopRated', Gtk.STOCK_FIND, _('_Top 40'), '', None, self._FilterMenu__filter_menu_actions),
('All', Gtk.STOCK_FIND, _('All _Songs'), '', None, self._FilterMenu__filter_menu_actions)])
for tag_, lab in [
('genre', _('Filter on _Genre')),
('artist', _('Filter on _Artist')),
('album', _('Filter on Al_bum'))]:
act = Gtk.Action.new('Filter%s' % util.capitalize(tag_), lab, None, Gtk.STOCK_INDEX)
act.connect('activate', self._FilterMenu__filter_on, tag_, None, player)
ag.add_action_with_accel(act, None)
for tag_, accel, label in [
('genre', 'G', _('Random _Genre')),
('artist', 'T', _('Random _Artist')),
('album', 'M', _('Random Al_bum'))]:
act = Gtk.Action.new('Random%s' % util.capitalize(tag_), label, None, Gtk.STOCK_DIALOG_QUESTION)
act.connect('activate', self._FilterMenu__random, tag_)
ag.add_action_with_accel(act, '<control>' + accel)
if not ui:
pass
ui = Gtk.UIManager()
ui.insert_action_group(ag, -1)
ui.add_ui_from_string(self._MENU)
self._ui = ui
ui.get_widget('/Menu/Filters/TopRated').set_tooltip_text(_("The 40 songs you've played most (more than 40 may be chosen if there are ties)"))
menu_item = ui.get_widget('/Menu/Filters')
if isinstance(menu_item, Gtk.ImageMenuItem):
menu_item.set_image(None)
self._player_id = player.connect('song-started', self._on_song_started)
self.set_song(player.song)
self._hide_menus()
def destroy(self):
if self._player:
self._player.disconnect(self._player_id)
self._player = None
self._browser = None
self._library = None
def _on_song_started(self, player, song):
self.set_song(song)
def __random(self, item, key):
self._browser.filter_random(key)
def __filter_on(self, action, header, songs, player):
if songs is None:
if player.song:
songs = [
player.song]
else:
return None
self._browser.filter_on(songs, header)
def __filter_menu_actions(self, menuitem):
name = menuitem.get_name()
if name == 'PlayedRecently':
self._make_query('#(lastplayed < 7 days ago)')
elif name == 'AddedRecently':
self._make_query('#(added < 7 days ago)')
elif name == 'TopRated':
bg = background_filter()
if not bg or filter(bg, self._library):
pass
songs = self._library
songs = [ song.get('~#playcount', 0) for song in songs ]
if len(songs) == 0:
return None
None.sort()
if len(songs) < 40:
self._make_query('#(playcount > %d)' % (songs[0] - 1))
else:
self._make_query('#(playcount > %d)' % (songs[-40] - 1))
elif name == 'All':
self._browser.unfilter()
def _make_query(self, query):
if self._browser.can_filter_text():
self._browser.filter_text(query.encode('utf-8'))
self._browser.activate()
def _hide_menus(self):
menus = {
'genre': [
'/Menu/Filters/FilterGenre',
'/Menu/Filters/RandomGenre'],
'artist': [
'/Menu/Filters/FilterArtist',
'/Menu/Filters/RandomArtist'],
'album': [
'/Menu/Filters/FilterAlbum',
'/Menu/Filters/RandomAlbum'],
None: [
'/Menu/Filters/PlayedRecently',
'/Menu/Filters/AddedRecently',
'/Menu/Filters/TopRated',
'/Menu/Filters/All'] }
for key, widgets in menus.items():
if self._browser:
can_filter = self._browser.can_filter(key)
else:
can_filter = False
for widget in widgets:
self._ui.get_widget(widget).set_property('visible', can_filter)
def set_browser(self, browser):
self._browser = browser
self._hide_menus()
def set_song(self, song):
for wid in [
'FilterAlbum',
'FilterArtist',
'FilterGenre']:
self._ui.get_widget('/Menu/Filters/' + wid).set_sensitive(bool(song))
if song:
for h in [
'genre',
'artist',
'album']:
self._ui.get_widget('/Menu/Filters/Filter%s' % h.capitalize()).set_sensitive(h in song)
def get_widget(self):
return self._ui.get_widget('/Menu')
def get_accel_group(self):
return self._ui.get_accel_group()
class LibraryBrowser(Window, util.InstanceTracker, PersistentWindowMixin):
def open(cls, Kind, library, player):
'''Creates and shows a new browser instance'''
browser = cls(Kind, library, player)
browser.show()
return browser
open = classmethod(open)
def save(cls):
'''See which browser windows are open and save their names
so we can restore them on start.
'''
names = []
for browser in cls.instances():
names.append(browser.name)
config.set('memory', 'open_browsers', '\n'.join(names))
save = classmethod(save)
def restore(cls, library, player):
'''restore saved browser windows'''
value = config.get('memory', 'open_browsers', '')
for name in value.split():
kind = browsers.get(name)
browser = cls(kind, library, player)
browser.show_maybe()
restore = classmethod(restore)
def __init__(self, Kind, library, player):
super(LibraryBrowser, self).__init__(dialog = False)
self._register_instance()
self.name = Kind.__name__
self.set_default_size(600, 400)
self.enable_window_tracking('browser_' + self.name)
self.set_title(Kind.name + ' - Quod Libet')
self.add(Gtk.VBox())
view = SongList(library, update = True)
view.info.connect('changed', self._LibraryBrowser__set_time)
self.songlist = view
sw = ScrolledWindow()
sw.set_shadow_type(Gtk.ShadowType.IN)
sw.add(view)
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.browser = browser = Kind(library)
if browser.reordered:
view.enable_drop()
elif browser.dropped:
view.enable_drop(False)
if browser.accelerators:
self.add_accel_group(browser.accelerators)
self._LibraryBrowser__container = browser.pack(sw)
self.get_child().pack_start(self._LibraryBrowser__container, True, True, 0)
main = self.get_child()
bottom = Gtk.HBox()
main.pack_end(bottom, False, True, 0)
self._filter_menu = filter_menu = FilterMenu(library, player)
filter_menu.set_browser(self.browser)
self.add_accel_group(filter_menu.get_accel_group())
bottom.pack_start(filter_menu.get_widget(), False, True, 0)
filter_menu.get_widget().show()
self._LibraryBrowser__statusbar = Gtk.Label()
self._LibraryBrowser__statusbar.set_text(_('No time information'))
self._LibraryBrowser__statusbar.set_alignment(1, 0.5)
self._LibraryBrowser__statusbar.set_padding(6, 3)
self._LibraryBrowser__statusbar.set_ellipsize(Pango.EllipsizeMode.START)
bottom.pack_end(self._LibraryBrowser__statusbar, True, True, 0)
self._LibraryBrowser__statusbar.show()
bottom.show()
browser.connect('songs-selected', self._LibraryBrowser__browser_cb)
browser.finalize(False)
view.connect('popup-menu', self._LibraryBrowser__menu, library)
view.connect('drag-data-received', self._LibraryBrowser__drag_data_recv)
view.connect('row-activated', self._LibraryBrowser__enqueue, player)
if browser.headers is not None:
view.connect('columns-changed', self._LibraryBrowser__cols_changed, browser)
self._LibraryBrowser__cols_changed(view, browser)
sw.show_all()
for c in self.get_child().get_children():
c.show()
self.get_child().show()
self.connect('destroy', self._on_destroy)
def _on_destroy(self, *args):
self._filter_menu.destroy()
def __browser_cb(self, browser, songs, sorted):
if browser.background:
bg = background_filter()
if bg:
songs = filter(bg, songs)
self.songlist.set_songs(songs, sorted)
def __enqueue(self, view, path, column, player):
app.window.playlist.enqueue([
view.get_model()[path][0]])
if player.song is None:
player.next()
def __drag_data_recv(self, view, *args):
if callable(self.browser.reordered):
self.browser.reordered(view)
view.clear_sort()
def __cols_changed(self, view, browser):
for header in view.get_columns():
tag = header.header_name
for t in util.tagsplit(tag):
if t in browser.headers:
header.set_visible(True)
break
continue
header.set_visible(False)
def __menu(self, view, library):
(path, col) = view.get_cursor()
header = col.header_name
menu = view.Menu(header, self.browser, library)
if menu is not None:
view.popup_menu(menu, 0, Gtk.get_current_event_time())
return True
def __set_time(self, info, songs):
i = len(songs)
length = sum((lambda .0: pass)(songs))
t = self.browser.statusbar(i) % {
'count': i,
'time': util.format_time_long(length) }
self._LibraryBrowser__statusbar.set_text(t)